package com.woniuxy.controller;

import com.woniuxy.dto.MenuDto;
import com.woniuxy.entity.User;
import com.woniuxy.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 权限管理
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;
    @Autowired
    private HttpSession session;

    @GetMapping("/findPermissionsByUserId")
    public ResponseEntity<List<MenuDto>> findPermissionsByUserId() {
        //会话域获取用户角色id
        User user = (User) session.getAttribute("user");
        //查询当前用户的菜单
        List<MenuDto> menus = permissionService.findPermissionsMenu(user.getId());
        return ResponseEntity.ok(menus);
    }
}
